
const TypeEnum={
    LI_CAI :"licai",
    QIAN_BAO:"qianbao",
    BAO_XIAN:"baoxian"
}

class Product{
    constructor(name,type){
        this.name = name
        this.type = type
    }
}


class IFilter {
    filter(channels){
        throw new Error()
    }
}

/***
 * 定开
 * 开放货币
 * 开放净值
 * 封闭型
 * 产品周期
 */
class LiCai extends IFilter{
    filter(channels){
        const returnList = []
        channels.forEach(element => {
            if(element.type ==TypeEnum.LI_CAI){
                returnList.push(element)
            }else if(element.type == TypeEnum.QIAN_BAO){
                returnList.push(element)
            }
        });
        return returnList
    }

}

/***
 * 
 * 开放货币型产品
 */
class QianBao extends IFilter{
    filter(channels){
        const returnList = []
        channels.forEach(element => {
            if(element.type ==TypeEnum.QIAN_BAO){
                returnList.push(element)
            }
        });
        return returnList
    }

}


/***
 * 
 * 保险产品
 */
 class BaoXian extends IFilter{
    filter(channels){
        //channels<Product>
        const returnList = []
        channels.forEach(element => {
            if(element.type ==TypeEnum.BAO_XIAN){
                returnList.push(element)
            }
        });
        return returnList
    }

}


/***
 * 
 * 开放货币产品
 */
 class KaiFangMoney extends IFilter{
    constructor(qianBao,liCai){
        super()
        this.qianBao = qianBao
        this.liCai = liCai
    }
    filter(channels){
        const qbFilter = this.qianBao.filter(channels)
        return this.liCai.filter(qbFilter)
    }
}


const product = new Product("理财子1",TypeEnum.LI_CAI)
const product2 = new Product("理财子2",TypeEnum.LI_CAI)
const product3 = new Product("保险3",TypeEnum.BAO_XIAN)
const product4 = new Product("钱包",TypeEnum.QIAN_BAO)

const qb = new QianBao()
const lc = new LiCai()
const array = [product,product2,product3,product4]

const kf = new KaiFangMoney(qb,lc)
console.log(kf.filter(array))

